﻿using System;
using System.Linq;
using System.Reflection;

namespace OperationPlugins.WebApp.Views
{
    public sealed class Layout
    {
        #region Private Fields

        private static string _productInfoText;

        #endregion

        /// <summary>
        /// Gets the layout for the current request.
        /// </summary>
        public static Layout Current
        {
            get { return ContextStorage.Get<Layout>(); }
        }

        /// <summary>
        /// Indicates if the current action is under the "Applications" category.
        /// </summary>
        public bool CurrentActionUnderApplications { get; set; }

        /// <summary>
        /// Indicates if the current action is under the "Event Logs" category.
        /// </summary>
        public bool CurrentActionUnderEventLogs { get; set; }
        
        /// <summary>
        /// Indicates if the current action is under the "Preferences" category.
        /// </summary>
        public bool CurrentActionUnderPreferences { get; set; }

        /// <summary>
        /// Gets the product info text.
        /// </summary>
        public string ProductInfoText
        {
            get
            {
                if (_productInfoText == null)
                {
                    Assembly app = typeof(Layout).Assembly;

                    AssemblyCopyrightAttribute copyright = (app.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true) as AssemblyCopyrightAttribute[]).First();

                    Version version = app.GetName().Version;

                    _productInfoText = string.Format("OperationPlugins Application Server, version {0}.{1}.{2} - {3} - Licenced under The MIT Licence (MIT)", 
                        version.Major,
                        version.Minor, 
                        version.Build,
                        copyright.Copyright);                    
                }                

                return _productInfoText;
            }
        }

        /// <summary>
        /// Gets the current theme name.
        /// </summary>
        public string Theme
        {
            get { return "United"; }
        }

        public bool InverseTheme { get { return false; } }
    }
}